<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
                             "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:s="http://jboss.com/products/seam/taglib"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:a="https://ajax4jsf.dev.java.net/ajax"
                xmlns:rich="http://richfaces.ajax4jsf.org/rich"
                template="layout/template.xhtml">
                       
<ui:define name="body">
    
    <h:messages globalOnly="true" styleClass="message" id="globalMessages"/>

    <h:form id="file" styleClass="edit">
    
        <rich:panel>
            <f:facet name="header">Edit File</f:facet>

           <s:decorate id="titleDecoration" template="layout/edit.xhtml">
               <ui:define name="label">title</ui:define>
               <h:inputText id="title"
                         value="#{fileHome.instance.title}">
                   <a:support event="onblur" reRender="titleDecoration" bypassUpdates="true"/>
               </h:inputText>
           </s:decorate>

           <s:decorate id="creationDateDecoration" template="layout/edit.xhtml">
               <ui:define name="label">creationDate</ui:define>
               <h:inputText
                     id="creationDate"
                     value="#{articleHome.instance.creationDate}"
                     converter="#{dateConverter}"
               >
                   <a:support event="onblur" reRender="creationDateDecoration" bypassUpdates="true"/>
               </h:inputText>
           </s:decorate>

            <div style="clear:both">
                <span class="required">*</span> 
                required fields
            </div>
            
        </rich:panel>
                
        <div class="actionButtons">

            <h:commandButton id="save" 
                          value="Save" 
                         action="#{fileHome.persist}"
                       disabled="#{!fileHome.wired}"
                       rendered="#{!fileHome.managed}"/>  
                          			  
            <h:commandButton id="update" 
                          value="Save" 
                         action="#{fileHome.update}"
                       rendered="#{fileHome.managed}"/>
                        			  
            <h:commandButton id="delete" 
                          value="Delete" 
                         action="#{fileHome.remove}"
                       rendered="#{fileHome.managed}"/>
                    
            <s:button id="done" 
                   value="Done"
             propagation="end"
                    view="/File.xhtml"
                rendered="#{fileHome.managed}"/>
                
            <s:button id="cancel" 
                   value="Cancel"
             propagation="end"
                    view="/#{empty fileFrom ? 'FileList' : fileFrom}.xhtml"
                rendered="#{!fileHome.managed}"/>

        </div>
    </h:form>

    <rich:tabPanel switchType="ajax">

        <rich:tab label="author">
        <div class="association" id="authorParent">

            <h:outputText value="No author"
                       rendered="#{fileHome.instance.author == null}"/>

            <rich:dataTable var="user"
                       value="#{fileHome.instance.author}"
                    rendered="#{fileHome.instance.author != null}"
                  rowClasses="rvgRowOne,rvgRowTwo"
                          id="authorTable">
                <h:column>
                    <f:facet name="header">id</f:facet>
                    #{user.id}
                </h:column>
                <h:column>
                    <f:facet name="header">username</f:facet>
                    #{user.username}
                </h:column>
                <h:column>
                    <f:facet name="header">password</f:facet>
                    #{user.password}
                </h:column>
                <h:column>
                    <f:facet name="header">name</f:facet>
                    #{user.name}
                </h:column>
                <h:column>
                    <f:facet name="header">action</f:facet>
                    <s:link view="/User.xhtml"
                             id="viewuser"
                          value="View"
                    propagation="none">
                        <f:param name="userId"
                               value="#{user.id}"/>
                    </s:link>
                </h:column>
            </rich:dataTable>

            <div class="actionButtons">
                <s:button value="Select author"
                           view="/UserList.xhtml">
                    <f:param name="from" value="FileEdit"/>
                </s:button>
            </div>

        </div>
        </rich:tab>
    </rich:tabPanel>

</ui:define>

</ui:composition>
